# -*- coding: utf-8 -*-
import getpass
from myFTPLib import MyFTP as myFtp

__author__ = 'Fonny'

def uploadFile():

	sHost = r'192.168.2.1'
	sUser = r'fonny'
	sPasswd = raw_input(r'Enter the passwd:')

	# 注意: getpass 必须在命令行下执行,不可用于 Pycharm 调试,但 Debug 可用
	# sPasswd = getpass.getpass()
	# print(sPasswd)

	if not sPasswd:
		exit()

	lFileName = r'AutoHotkey.exe'
	sFileName = r'/sda1/uploads/AutoHotkey.exe'

	con = myFtp()
	# con.ConnectFTP(sHost, 21, sUser, sPasswd)
	con.upload(sHost, 21, sUser, sPasswd, sFileName, lFileName)

def showRemoteFile():
	from ftplib import FTP
	sHost = r'192.168.2.1'
	sUser = r'fonny'
	sPasswd = raw_input('Enter the passwd:')

	# 注意: getpass 必须在命令行下执行,不可用于 Pycharm 调试,但 Debug 可用
	# sPasswd = getpass.getpass()
	# print(sPasswd)

	if not sPasswd:
		exit()
	sPath = r'/sda1/uploads'
	con = FTP(sHost)
	try:
		con.login(sUser, sPasswd)
		# print(con.nlst())

		con.cwd(sPath)
		# con.cwd('sda1')
		print(con.retrlines('LIST'))
		# flist = con.nlst()
		# print(flist)
	except Exception, e:
		print(e)
	finally:
		con.quit()


def main():
	uploadFile()
	showRemoteFile()

if __name__ == '__main__':
	main()
